package com.junko.service.back.impl;

import com.junko.core.base.BaseServiceImpl;
import com.junko.dao.back.GroupDao;
import com.junko.model.back.Group;
import com.junko.service.back.IAdminService;
import com.junko.service.back.IGroupService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GroupService extends BaseServiceImpl<Group> implements IGroupService {
    @Autowired
    private GroupDao groupDao;
    @Resource
    private IAdminService adminService;

    @Override
    public List<Group> findByGroupIds(String groupIds) {
        return groupDao.findByGroupIds(StringUtils.split(groupIds,","));
    }

    /**
     * 用户组选择
     * @param id 用户id
     */
    @Override
    public Map<String,Object> select(String id){
        List<Group> noCheckedList;
        List<Group> checkedList = new ArrayList<>();
        String groupId = adminService.selectByPrimaryKey(id).getGroupIds();
        if(null != groupId && !groupId.equals("")){
            noCheckedList = groupDao.findNoChecked(groupId.split(","));
            checkedList = groupDao.findChecked(groupId.split(","));
        }else{
            noCheckedList = groupDao.findAllNoChecked();
        }

        Map<String,Object> map = new HashMap<String,Object>();
        map.put("noCheckedList", noCheckedList);
        map.put("checkedList", checkedList);
        return map;
    }
}